#include<iostream>
#include<unistd.h>
#include<signal.h>
#include<sys/wait.h>
using namespace std;
void notice(int sig)
{
    int flag = 0;
    while (!flag)
    {
        pid_t id = waitpid(-1, nullptr, WNOHANG);
        if(id>0)
        {
            cout <<id<< " child quit!" << endl;
        }
        else
            flag = 1;
    }
}
int main()
{
    signal(SIGCHLD, notice);
    int ct = 5;
    while(ct--)
    {
        pid_t id = fork();
        if(id==0)
        {
            cout << "i am child" << endl;
            sleep(1);
            exit(1);
        }
    }
    int cnt = 10;
    while(cnt--)
    {
        cout << "father" << endl;
        sleep(1);
    }
    cout << "over!" << endl;
    return 0;
}